/**
 * Created by Fanjiang Huang on 2016/7/19.
 */

$(function(){

    //载入导航
    $('footer').load('footer.html', function () {
        $('.icon-game').parent().addClass('nav-now');
        $('footer nav li a').click( function (){
            $(this).parent().siblings().find('a').removeClass('nav-now');
            $(this).addClass('nav-now');
        });
    });

    //选项卡
    var tabsSwiper = new Swiper('.tabs-con',{
        autoHeight: true,
        speed:500,
        onSlideChangeStart: function(){
            $(".tabs .active").removeClass('active');
            $(".tabs a").eq(tabsSwiper.activeIndex).addClass('active');
        }
    });

    $(".tabs a").on('touchstart mousedown',function(e){
        e.preventDefault();
        $(".tabs .active").removeClass('active');
        $(this).addClass('active');
        tabsSwiper.slideTo($(this).index());
    });

    $(".tabs a").click(function(e){
        e.preventDefault();
    });

    //头部悬停
    var windowHeight = $(window).height();
    var headerHeight = $('header').height();
    var footerHeight = $('footer').height();
    var tabsHeight = $('.tabs').height();

    $('.tabs-con').css('height',windowHeight - headerHeight - footerHeight - tabsHeight );
    $('.tabs-con .content-slide').css('height',windowHeight - headerHeight - footerHeight - tabsHeight );

    $(window).scroll(function(){
        var bannerLong = $('.banner').height();
        var menuLong = $('.menu-box').height();
        var sectionScroll = $(this).scrollTop();
        var wayScroll = bannerLong + menuLong;

        if (sectionScroll >= wayScroll) {
            $('.tabs-con .content-slide').css('overflow-y', 'auto');
        } else {
            $('.tabs-con .content-slide').css('overflow-y', 'hidden');
        }
    });

});
